package io.finer.erp.jeecg.bas.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.finer.erp.jeecg.bas.entity.Region;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: region
 * @Author: jeecg-boot
 * @Date:   2021-07-21
 * @Version: V1.0
 */
public interface RegionMapper extends BaseMapper<Region> {

	/**
	 * @Description 查询该分类下的所有子节点
	 * @param rootId
	 * @return
	 * Create at: 2021-07-21 09:30:32
	 * @author: xzs
	 * Revision:
	 *    2021-07-21 09:30:32 - first revision by xzs
	 *
	 */
	@Select("select * from region where id in (select id from (select t1.id, if(find_in_set(pid, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild from (select id,pid from region t order by pid,id) t1,(select @pids := #{rootId}) t2 ) t3 where ischild != 0)")
	List<Region> getAllChildRegionHasChild(@Param("rootId")String rootId);
}
